<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/include.inc.jsp" %>

<link rel="stylesheet" href="${ctx}/static/meeting/controls/subGrid/subgrid.css"/>
<form method="post" id="customesearchform${index}" action="${ctx}/customsearch/dialogsearch" style="min-height: 500px;">
    <div class="col-xs-12">
        <div class="mtrow">
            <div class="mtcolall">
                <c:forEach items="${listControl}" var="con">
                    <c:if test="${not empty con.controlName}">
                        <label class="mtlabel-auto">${con.controlName}：</label>
                        <c:choose>
                            <c:when test="${con.controlType == 0}">
                                <input type="text" class="mtinput" name="${con.fieldName}"
                                       controltype="${con.controlType}"
                                       value="${con.qcDefault}"/>
                            </c:when>
                            <c:when test="${con.controlType == 1}">
                                <input type="text" class="mtinput" name="${con.fieldName}"
                                       controltype="${con.controlType}"
                                       value="${con.qcDefault}"/>
                            </c:when>

                        </c:choose>
                    </c:if>
                </c:forEach>
                <c:if test="${fn:length(listControl) > 0}">
                    <a class="mtbtn search marginleft dialogsearch${index}" href="#"><i
                            class="mtfa mt-search"></i><span>查询</span></a>
                </c:if>
            </div>
        </div>
        <div>
            <table id="customsearchgrid${index}" style="margin-top: 10px;">
            </table>
        </div>
    </div>
    <div class="defaultparam${index}" style="display: none;">${defaultParam}</div>
    <div class="getresultBtn${index}"></div>
    <input type="hidden" class="contentidHid${index}"/>
    <input type="hidden" class="resultHid${index}"/>
</form>
</body>
</html>
<script src="${ctx}/static/meeting/controls/subGrid/jquery.subgrid.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        var subgridid="#customsearchgrid${index}";
        var result = [{"result1": ""}, {"result2": ""}, {"result3": ""}, {"result4": ""}, {"result5": ""}, {"result6": ""}, {"result7": ""}, {"result8": ""}, {"result9": ""}, {"result10": ""}];
        //子表控件对象
        var SubGrid;
        var option = {
            idField: "is",
            data: "",
            columns: ${columns},
            data: ${data},
            checkBox: false,
            select: true,
            rowCommon: {
                selectfun: function (index) {
                    var data = SubGrid.getAllRows();
                    if (data.length == 0) {
                        layer.msg("请选择数据", {icon: 3});
                    } else {
                        result = data;
                        $(".resultHid${index}").val(JSON.stringify(result[index]));
                    }
                    $("#" + $(".contentidHid${index}").val()).parent().parent().find(".jconfirm-buttons .btn-blue").click();
                }
            }
        }

        SubGrid = $(subgridid).subgrid(option).data("subgrid");

        $(".dialogsearch${index}").click(function () {

            $.ajax({
                type: "POST",
                url: "${ctx}/customsearch/dialogsearch",
                contentType: "application/json",
                data: JSON.stringify({
                    sqlmapId: "${sqlmapId}",
                    searchstringparam: $("#customesearchform${index} .mtcolall :input[controltype='0']").serializeArray(),
                    searchvalueparam: $("#customesearchform${index} .mtcolall :input[controltype='1']").serializeArray(),
                    defaultParam: JSON.parse($("#customesearchform${index} .defaultparam${index}").html())
                }),
                success: function (result) {
                    option.data = JSON.parse(result);
                    SubGrid = $(subgridid).subgrid(option).data("subgrid");
                }
            })
        });

    })

</script>

